package org.bemo.utils;

import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;

import com.sun.tools.jdi.LinkedHashMap;

public class MapDataCache {
	private static LinkedHashMap cacheMap;

	public static Object getCache(String key, Object defaultValue) {
		Object obj = getCacheMap().get(key);
		return obj == null ? defaultValue : obj;
	}

	public static void putCache(String key, Object value) {
		// 每添加一个视频就删除一个,最多缓存500个
		if (null != cacheMap && cacheMap.size() > 500) {
			for (int i = getCacheMap().keySet().size(); i > 0; i--) {
				getCacheMap().remove(String.valueOf(i));// 删除最后一个
			}
		}
		getCacheMap().put(key, value);
	}

	public static void removeCache(String key) {
		getCacheMap().remove(key);
	}

	public static Map<String, Object> getCacheMap() {
		if (cacheMap == null) {
			cacheMap = new LinkedHashMap();
		}
		return cacheMap;
	}
}